<template>
  <el-row :gutter="20">
    <el-col :span="8"  v-for="i in CardsData_show" style="padding-top: 10px">
      <CompanyCard
        :title="i.enterprise_name"
        :img_src="i.enterprise_website"
        :company_address="i.enterprise_address"
        :company_style="i.industry"
        :company_years="i.enterprise_website"
        :company_id="i.enterprise_infor_id"
      ></CompanyCard>
    </el-col>
  </el-row>
</template>

<script>

import CompanyCard from './CompanyCard'
import axios from 'axios'

export default {
  name: 'CompanyCards',
  components:{CompanyCard},
  data(){
    return{
      CardsData:[],
      CardsData_show:[]
    }
  },
  methods:{
    deteleObject(obj) {
      var uniques = [];
      var stringify = {};
      for (var i = 0; i < obj.length; i++) {
        var keys = Object.keys(obj[i]);
        keys.sort(function(a, b) {
          return (Number(a) - Number(b));
        });
        var str = '';
        for (var j = 0; j < keys.length; j++) {
          str += JSON.stringify(keys[j]);
          str += JSON.stringify(obj[i][keys[j]]);
        }
        if (!stringify.hasOwnProperty(str)) {
          uniques.push(obj[i]);
          stringify[str] = true;
        }
      }
      uniques = uniques;
      return uniques;
    }
  },
  created () {
    const _this=this
    axios.get('http://localhost:8080/get_enterprise_info_show')
      .then(function (response) {
        _this.CardsData=response.data

        for (let i = 0 ; i < _this.CardsData.length ; i = i + 1){
          _this.CardsData[i].enterprise_website = 'http://' + _this.CardsData[i].enterprise_website
         // console.log(_this.CardsData[i].enterprise_website)
        }
        let i=0

        sessionStorage.setItem('company_data_in_search',JSON.stringify(_this.CardsData))
        //console.log(sessionStorage.getItem('company_data_in_search'))

        sessionStorage.setItem('all_enterprise_name','')
        for (;i < _this.CardsData.length;i=i+1){
          let temp = ''
          temp = sessionStorage.getItem('all_enterprise_name')
          if(i > 0){
            temp = temp + '，'
          }
          temp = temp + _this.CardsData[i].enterprise_name
          sessionStorage.setItem('all_enterprise_name',temp)
        }

        if(sessionStorage.getItem('company_data_out_search')){
          _this.CardsData_show=JSON.parse(sessionStorage.getItem('company_data_out_search'))
          //console.log(sessionStorage.getItem('company_data_out_search'))
          let temp = JSON.parse(JSON.stringify(_this.CardsData_show))

          _this.CardsData_show = _this.deteleObject(_this.CardsData_show)

        }else {
          _this.CardsData_show = JSON.parse(JSON.stringify(_this.CardsData))
        }

      })
      .catch(function (error) {
        console.log(error);
      });
  }
}
</script>

<style scoped>

</style>
